package com.example.observer.dubbo;

import java.lang.reflect.Modifier;

// manage listener
public interface Listenable<E extends EventListener> {


    void addEventListener(E listener) throws NullPointerException, IllegalArgumentException;

    void removeEventListener(E listener) throws NullPointerException, IllegalArgumentException;


    static void assertListener(EventListener<?> listener) throws NullPointerException {
        if (listener == null) {
            throw new NullPointerException("The listener must not be null.");
        }

        Class<?> listenerClass = listener.getClass();

        int modifiers = listenerClass.getModifiers();

        if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) {
            throw new IllegalArgumentException("The listener must be concrete class");
        }
    }
}
